package movieGandalf.dataObjects;

import java.sql.Connection;

import movieGandalf.database.MovieTools;
import movieGandalf.logicGuiConnection.Genre;

public class GenreImp implements Genre{
	
	private Integer id;
	
	private String genre;
	
	public GenreImp(Integer id, String genre){
		this.id = id;
		this.genre = genre;
	}
	
	public Integer getID() {
		return this.id;
	}

	public String getGenre() {
		if (genre != null)
			return genre;
		
		if (id == null)
			return null;
		
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return null;
		
		genre = MovieTools.getGenre(conn, this.id);
		
		return genre;
	}

	public void setID(Integer newID) {
		this.id = newID;
		
	}
	
	public void setGenre(String newGenre) {
		this.genre = newGenre;
	}

	public boolean update() {
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.updateGenre(conn, this);
	}
	
	public boolean delete() {
		Connection conn = MovieTools.getConn();
		if (conn==null)
			return false;
		
		return MovieTools.deleteObject(conn,this);
	}
}
